/*
 * Copyright (c) 2006-2021, Halo team
 *
 * SPDX-License-Identifier: GPLv3
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-09-11     Eywen        the first version
 */

#ifndef APPLICATIONS_HEATER_H_
#define APPLICATIONS_HEATER_H_

#include "drivers/drv_pid.h"
#include "temperature.h"
#include <rtthread.h>

typedef enum heater_type{
    heater_type_normal,
}heater_type_t;

typedef struct _heater_ops heater_ops_t;

typedef struct _heater{
    pid_control_t *pid;              /* 加热pid */

    int pin_heater;                  /* 加热控制引脚 */
    bool heater_level;               /* 加热有效电平  */
    temperature_t *temperature;      /* 温度接口 */

    const heater_ops_t *ops;
    rt_timer_t timer;                /* 任务定时器 */
}heater_t;

typedef struct _heater_ops{
    bool (*init)(heater_t *heater, int pin_heater, bool heater_level,
                 uint32_t time_interval, temperature_t *temperature_sensor);
    void (*schedule_task)(void *parameter);
    void (*start)(heater_t *heater);
    void (*stop)(heater_t *heater);
    void (*target_set)(heater_t *heater, float target);
    float (*target)(heater_t *heater);
}heater_ops_t;

bool heater_register(heater_t *heater);
heater_t *heater_create(pid_type_t pid_type);

#endif /* APPLICATIONS_HEATER_H_ */
